﻿using System;
using System.Collections.Generic;
using System.Linq;

class HowManyTimesALetterIsFoundInString
{
    static void Main()
    {
        //Exercise 21.
        //Write a program that reads a string from the console and prints all different letters in the string along with 
        //information how many times each letter is found. 

        //Console.Write("Type the text: ");
        //string text = Console.ReadLine();
        string text = "Write a program that reads a string from the console and prints all different letters in the string.";

        string[] specialSigns = { " ", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "-", "_", "+", "." };

        for (int i = 0; i < specialSigns.Length; i++)
        {
            text = text.Replace(specialSigns[i], string.Empty);
        }

        Dictionary<char, int> allLetters = new Dictionary<char, int>();

        for (int i = 0; i < text.Length; i++)
        {
            if (allLetters.ContainsKey(text[i]))
            {
                allLetters[text[i]]++;
            }
            else
            {
                allLetters.Add(text[i], 1);
            }
        }

        var sortedLetters = allLetters.OrderBy(x => x.Key);
        foreach (var item in sortedLetters)
        {
            Console.WriteLine("Letter -> {0} - Counter -> {1}", item.Key, item.Value);
        }

    }
}

